<template>
	<view class="fillBox">
		<!-- <view class="title">
			添加经销商
		</view> -->
		<!-- 填报内容 -->
		<view class="fillContent">
			<view class="fillContentBox">
				<view class="numType">
					<view class="numType1">数据类型:</view>
					<view class="numType2">经销商数据</view>
				</view>
				<view class="wire"></view>
				<view class="nameBox">
					<view class="nameBox1">姓名:</view>
					<input type="text" v-model="name" class="nameBox2" placeholder="请输入姓名" />
				</view>
				<view class="wire"></view>
				<view class="nameBox">
					<view class="nameBox1">电话:</view>
					<input type="text" v-model="phone" class="nameBox2" placeholder="请输入手机号" />
				</view>
				<view class="wire"></view>

				<!-- 	<view class="wire">
					
				</view> -->
				<view class="nameBoxa">
					<view class="nameBoxa1">登录密码:</view>
					<input type="text" v-model="model" class="nameBoxa2" placeholder="请输入登录密码" />
				</view>
				<view class="wire"></view>
				<view class="nameBoxa">
					<view class="nameBoxa1">所属地担:</view>
					<input type="text" :disabled="true" v-model="address" class="nameBoxa2" placeholder="请输入所属地担" />
				</view>
				<view class="wire"></view>
				<view class="nameBoxa">
					<view class="nameBoxa1">所属门店:</view>
					<view class="uni-list-cell-db" style="flex: 1;">
						<picker @change="bindPickerChange" :value="index" :range="array">
							<view class="uni-input">{{ array[index] }}</view>
						</picker>
					</view>
				</view>
				<view class="wire"></view>
				<!-- 	<view class="nameBoxa">
					<view class="nameBoxa1">
						所属区域:
					</view>
					<input type="text" v-model="area" class="nameBoxa2"  placeholder="请输入所属区域"/>
				</view>
			<!-- 	<view class="wire">
					
				</view> -->
				<!-- 
				<view class="wire">
					
				</view> -->
				<view class="btn" @click="submitClick">确定修改</view>
			</view>
		</view>
	</view>
</template>

<script>
import { regionDistributorDetails, regionAddEdit, regionStoreList } from '@/request/api.js';
export default {
	data() {
		return {
			name: '', //姓名
			phone: '',
			model: '', //购买车型
			remarks: '',
			obj: {},
			address: '',
			mendian: '',
			area: '',
			id: '',
			mednianObj: {},
			array: [],
			index: 0,
			arrayS:[],
			mendianId:''
		};
	},
	onLoad(option) {
		if (option.id) {
			this.init(option.id);
			this.id = option.id;
			this.obj = uni.getStorageSync('regionMessage');
			this.address = this.obj.sheng + this.obj.shi + this.obj.qu;
		}
	},
	onShow() {},
	methods: {
		//数据初始化
		init(id) {
			let _this = this;
			let data = {
				id: id
			};
			regionDistributorDetails(data)
				.then(res => {
					if (res.code == 1) {
						_this.name = res.data.name; //姓名
						_this.phone = res.data.mobile; //登录手机号
						_this.model = res.data.password; //登录密码
						_this.mendian = res.data.city; //所属门店
						_this.area = res.data.area; //所属门店
						_this.mednianObj = res.data;
						_this.mendian = res.data.stores;
						_this.mendianId = res.data.store;
					} else {
					}
				})
				.catch(err => {
					console.log(err);
				});
			regionStoreList()
				.then(res => {
					if (res.code == 1) {
						_this.array=[]
						// console.log(res, '123123123123');
						_this.arrayS=res.data;
						
						for(let i=0;i<res.data.length;i++){
							// console.log(res.data[i])
							_this.array.push(res.data[i].stores)
						}
						_this.arrayS.forEach((item,indexs)=>{
							if(itme.id==_this.mendianId){
								_this.index=indexs
							}
						})
					}
				})
				.catch(err => {});
		},
		submitClick() {
			let _this = this;
			if (_this.name == '' || _this.phone == '' || _this.model == '') {
				uni.showToast({
					title: '请填写完整信息',
					icon: 'none'
				});
				return;
			}
			let data = {
				regional_id:_this.obj.id,
				store: _this.mendianId,
				name: _this.name,
				mobile: _this.phone,
				password: _this.model,
				id: _this.id
			};
			regionAddEdit(data)
				.then(res => {
					if (res.code == 1) {
						uni.navigateBack({
							delta: 1
						});
						setTimeout(() => {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}, 1000);
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})
				.catch(err => {
					console.log(err);
				});
		},
		bindPickerChange: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value);
			let _this =this
			this.index = e.target.value;
			this.arrayS.forEach((item,idnexs) =>{
				if(e.target.value==idnexs){
					_this.mendianId = item.id
				}
			})
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #ffffff;
}
.fillBox {
	width: 100%;
	box-sizing: border-box;
	padding-bottom: 40rpx;
	overflow: hidden;
	position: relative;
	.title {
		width: 100%;
		text-align: center;
		margin-top: 54rpx;
		font-size: 38rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #313233;
	}
	.fillContent {
		width: 100%;
		overflow: hidden;
		.fillContentBox {
			width: 622rpx;
			margin: 30rpx auto 0;
			.numType {
				width: 100%;
				display: flex;
				overflow: hidden;
				.numType1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					margin-right: 80rpx;
				}
				.numType2 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
				}
			}

			.wire {
				width: 100%;
				height: 4rpx;
				background-color: #e9e9ec;
				margin-top: 28rpx;
			}
			.nameBox {
				width: 100%;
				display: flex;
				overflow: hidden;
				margin-top: 40rpx;
				.nameBox1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					margin-right: 156rpx;
				}
				.nameBox2 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					flex: 1;
				}
			}
			.nameBoxa {
				width: 100%;
				display: flex;
				overflow: hidden;
				margin-top: 40rpx;
				.nameBoxa1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					margin-right: 84rpx;
				}
				.nameBoxa2 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					flex: 1;
				}
			}
			.remarks {
				width: 100%;
				display: flex;
				overflow: hidden;
				margin-top: 40rpx;
				.remarks1 {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					margin-right: 150rpx;
				}
				.remarks2 {
					width: 386rpx;
					height: 230rpx;
					border: 1px solid #e9e9ec;
				}
			}
			.btn {
				width: 460rpx;
				height: 80rpx;
				background: #1855f6;
				border-radius: 40rpx;
				// margin-top: 122rpx;
				margin: 122rpx auto 0;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
				line-height: 80rpx;
				text-align: center;
			}
		}
	}
}
</style>

